// https://nuxt.com/docs/api/configuration/nuxt-config
import sitemap from './utils/sitemap'
export default defineNuxtConfig({
  compatibilityDate: '2024-07-10',
  devtools: { enabled: true },
  sitemap,
  app: {
    // head配置
    head: {
      title: import.meta.env.VITE_SITE_TITLE,
      charset: 'utf-8',
      viewport: 'width=device-width, initial-scale=1',
      htmlAttrs: {
        lang: 'zh',
      },
      meta: [
        { name: 'viewport', content: 'width=device-width, initial-scale=1, user-scalable=no' },
        { name: 'screen-orientation', content: 'portrait' },
      ],
      script: [
      ],
    }
  },
  css: [
    // 全局样式
    '@/assets/style/app.scss',
    '@/assets/style/theme.scss',
    '@/public/icons/cms/iconfont.css'
  ],
  vite: {
    css: {
      // 修复启动时出现The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.
      preprocessorOptions: {
        scss: {
          api: 'modern-compiler'
        }
      }
    },
    // 接口代理配置
    server: {
      proxy: {
        // 接口代理
        [import.meta.env.VITE_API_PREFIX]: {
          target: import.meta.env.VITE_API_URL,
          changeOrigin: true,
          rewrite: (path:any) => path.replace(new RegExp(`^${import.meta.env.VITE_API_PREFIX}`), '')
        },
        // 资源代理
        [import.meta.env.VITE_RESOURCE_PREFIX]: {
          target: `${import.meta.env.VITE_API_URL}${import.meta.env.VITE_RESOURCE_PREFIX}`,
          changeOrigin: true,
          rewrite: (path:any) => path.replace(new RegExp(`^${import.meta.env.VITE_RESOURCE_PREFIX}`), '')
        }
      },
    }
  },
  // 扩展内容
  modules: [
    'dayjs-nuxt',
    '@element-plus/nuxt',
    // 导入element-plus图标
    '@pinia/nuxt',
    'nuxt-swiper',
    '@nuxtjs/sitemap'
  ],
  plugins: [
    '~/plugins/nprogress.js',
    '~/plugins/messagebox.js',
    '~/plugins/nprogress.js',
  ]
})
